/* **********************************************************
 * Copyright 2010 Dimitar Vangelovski
 *
 * This file is part of the Gens3 3D Engine.
 * 
 * The Gens3 3D Engine is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 * 
 * The Gens3 3D Engine is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with the Gens3 3D Engine; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA
 * **********************************************************/


#pragma once

#include <vector>

class CScene;

// Transparent polygons data
struct STrData
{
	int	iGeomIndex;
	int	iFaceIndex;

	// Average polygon vertex taken from all the polygon vertices
	float	x;
	float	y;
	float	z;

	// Transformed vertex coordinates with the MODELVIEW matrix
	// The Z coordinate from this vertex will be used to sort the polygons back-to-front
	float	xv;
	float	yv;
	float	zv;
};

class CDrawGL
{
public:

	CDrawGL();
	~CDrawGL();

	bool	InitializeGL(CScene * pScene);
	void	DeinitializeGL();
	void	DrawNonTransparentSurfaces(CScene * pScene);
	void	DrawTransparentSurfaces(CScene * pScene);
	void	AnimateObjects(CScene * pScene);

private:
	// Transparent polygon functions
	inline void	TrSwap(int i, int j) { STrData trTemp = m_TrData[i]; m_TrData[i] = m_TrData[j]; m_TrData[j] = trTemp; }
	void		TrQSort(int l, int r);
	void		TrTransform();
	void		TrInit(CScene * pScene);

private:
	std::vector<STrData>	m_TrData;
};

